import type { IOrderTime } from "@/utils/types";
import type { ProColumns } from "@ant-design/pro-components";
import { Popconfirm, Space } from "antd";

export type TWeek =
  | "monday"
  | "tuesday"
  | "wednesday"
  | "thursday"
  | "friday"
  | "saturday"
  | "sunday";

export interface IDay {
  key: TWeek;
  label: string;
}

export const DAYS: IDay[] = [
  { key: "monday", label: "周一" },
  { key: "tuesday", label: "周二" },
  { key: "wednesday", label: "周三" },
  { key: "thursday", label: "周四" },
  { key: "friday", label: "周五" },
  { key: "saturday", label: "周六" },
  { key: "sunday", label: "周日" },
];

export const getOrderTimeColumns: (
  onDeleteHandler: (id: any) => void
) => ProColumns<IOrderTime, "text">[] = (onDeleteHandler) => {
  return [
    {
      title: "序号",
      dataIndex: "key",
      // key: "name",
      width: 50,
      editable: false,
      align: "center",
    },
    {
      title: "开始时间",
      dataIndex: "startTime",
      valueType: "time",
      // key: "limitNumber",
      width: 160,
      search: false, //关闭搜索
      align: "center",
    },
    {
      title: "结束时间",
      dataIndex: "endTime",
      valueType: "time",
      width: 75,
      search: false,
      align: "center",
    },
    {
      title: "操作",
      valueType: "option",
      align: "center",
      width: 200,
      // action可以用于调用
      render: (_text, record, _, action) => (
        <Space>
          <a
            key="edit"
            onClick={() => {
              action?.startEditable(record.key);
            }}
            // onClick={() => onDeleteHandler(entity.id)}
          >
            编辑
          </a>
          <Popconfirm
            title="提醒"
            description="确认要删除吗？"
            onConfirm={() => onDeleteHandler(record.key)}
          >
            <a
              key="delete"
              // onClick={() => onDeleteHandler()}
            >
              删除
            </a>
          </Popconfirm>
        </Space>
      ),
    },
  ];
};

export const isWorkDay = (day: string) => [
  "monday",
  "tuesday",
  "wednesday",
  "thursday",
  "friday",
  // "saturday",
  // "sunday",
].includes(day);
